/*=============================================================================
#    The element-comm is a tentative program used to test our ideas.           
#                       Copyright (C)  bgao                                    
#
#     This program is free software; you can redistribute it and/or            
#      modify it under the terms of the GNU General Public License             
#     as published by the Free Software Foundation; either version 2           
#         of the License, or (at your option) any later version.               
#
#     This program is distributed in the hope that it will be useful,          
#    but WITHOUT ANY WARRANTY; without even the implied warranty of           
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the            
#             GNU General Public License for more details.                    
#
#    You should have received a copy of the GNU General Public License        
#     along with this program; if not, write to the Free Software             
#      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,             
#                       MA  02110-1301, USA.                                  
#==============================================================================
# $Id: mac_parse.h 348 2010-11-29 09:01:16Z bgao $ 
#
# $Author: bgao $ 
#
# $Revision: 348 $ 
#
# $Date: 2010-11-29 17:01:16 +0800 (星期一, 29 十一月 2010) $ 
#
# Description: 
#
=============================================================================*/
/*! @file mac_parse.h
 *  @brief This file defines the interfaces for the parsef module,
 *         and defines the constants used when parsing.
 */
#ifndef _MAC_PARSE_H_
#define _MAC_PARSE_H_

#include "mac.h"

#define MAC_FRM_TYPE_MASK          (0b11    <<  MAC_FRM_TYPE_OFFSET)
#define MAC_EN_SEC_MASK            (0b1     <<  MAC_EN_SEC_OFFSET)
#define MAC_FRM_PEND_MASK          (0b1     <<  MAC_FRM_PEND_OFFSET)
#define MAC_ACK_MASK               (0b1     <<  MAC_ACK_OFFSET)
#define MAC_PAN_ID_COMP_MASK       (0b1     <<  MAC_PAN_ID_COMP_OFFSET)
#define MAC_DEST_ADDR_M_MASK       (0b11    <<  MAC_DEST_ADDR_M_OFFSET)
#define MAC_FRM_VER_MASK           (0b11    <<  MAC_FRM_VER_OFFSET)
#define MAC_SRC_ADDR_M_MASK        (0b11    <<  MAC_SRC_ADDR_M_OFFSET)

#define MAC_BCN_ORDER_MASK         (0b1111  <<  MAC_BCN_ORDER_OFFSET)
#define MAC_SUP_FRM_ORDER_MASK     (0b1111  <<  MAC_SUP_FRM_ORDER_OFFSET)
#define MAC_FNL_CAP_SLOT_MASK      (0b1111  <<  MAC_FNL_CAP_SLOT_OFFSET)
#define MAC_BLE_MASK               (0b1     <<  MAC_BLE_OFFSET)
#define MAC_PAN_COORD_MASK         (0b1     <<  MAC_PAN_COORD_OFFSET)
#define MAC_ASSOC_PMIT_MASK        (0b1     <<  MAC_ASSOC_PMIT_OFFSET)

#define ALTNT_PAN_COORD_MASK       (0b1     <<  ALTNT_PAN_COORD_OFFSET)
#define DEV_TYPE_MASK              (0b1     <<  DEV_TYPE_OFFSET)
#define PW_SRC_MASK                (0b1     <<  PW_SRC_OFFSET)
#define REC_ON_WHEN_IDLE_MASK      (0b1     <<  REC_ON_WHEN_IDLE_OFFSET)
#define SEC_CAP_MASK               (0b1     <<  SEC_CAP_OFFSET)
#define ALLOC_ADDR_MASK            (0b1     <<  ALLOC_ADDR_OFFSET)

/*! MAC frame control sequence type */
typedef struct mac_fcs_t_ {
    uint8 rssi;
    bool  is_crc_ok;
    uint8 corr_value;
} mac_fcs_t;

uint8 mac_parse_frm_ctrl(uint16 value, mac_frm_ctrl_t *ctrl);
int8 mac_parse_hdr(buf_t *buf, mac_hdr_t *hdr);
uint8 mac_parse_sup_frm(uint16 value, mac_sup_frm_t *sup_frm);
uint8 mac_parse_cap_info(uint8 value, mac_cap_info_t *cap_info);
int8 mac_parse_bcn(buf_t *buf, mac_frm_bcn_t *bcn);
int8 mac_parse_assoc_req(buf_t *buf, mac_frm_assoc_req_t *req);
int8 mac_parse_assoc_resp(buf_t *buf, mac_frm_assoc_resp_t *resp);
uint8 mac_parse_cmd(buf_t *buf);
int8 mac_parse_fcs(buf_t *buf, mac_fcs_t *fcs);
#endif

